﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;

namespace AKJ.Sharepoint.Branding.Config
{
    public class SPProperties
    {
        private Microsoft.SharePoint.Utilities.SPPropertyBag properties;
        private SPWeb web;

        public SPProperties(Microsoft.SharePoint.SPWeb webCurrent)
            : base()
        {
            this.web = webCurrent;
            properties = CurrentWeb.Properties;
        }

        public bool ExistsKey(string key)
        {
            return properties.ContainsKey(key);
        }

        public string GetValue(string key)
        {
            if (ExistsKey(key))
            {
                return (string)properties[key];
            }
            else
            {
                return string.Empty;
            }
        }

        public void SetValue(string key, string Value)
        {
            if (ExistsKey(key))
            {
                properties[key] = Value;                
            }
            else
            {
                properties.Add(key, Value);
            }

            properties.Update();
        }

        public void DeleteKey(string key)
        {
            properties.Remove(key);
            properties.Update();
        }

        public Microsoft.SharePoint.SPWeb CurrentWeb
        {
            get { return web; }
            set { web = value; }
        }
    }
}
